//
//  HOPMainController.swift
//  WB01
//
//  Created by HOP on 15/12/15.
//  Copyright © 2015年 HOP. All rights reserved.
//

import UIKit

class HOPMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
//        view.tintColor = UIColor.orangeColor()
        // 自定义tabbar,是只读的,不能直接使用 = 进行赋值
        // KVC 进行替换
        let mainTabBar = HOPMainTabBarController()
        mainTabBar.CallBack = { () -> () in
            if HOPuserAccount.userLogin {
                let composeVC = HOPComposeViewController()
                self.presentViewController(UINavigationController(rootViewController: composeVC), animated: true, completion: nil)
            
            }else {
                // 创建登陆界面
                let oauthVC = HOPOauthViewController()
                // 弹出登陆界面,包装导航控制器
                self.presentViewController(UINavigationController(rootViewController: oauthVC), animated: true, completion: nil)
            }
        
        }
        
        setValue(mainTabBar, forKey: "tabBar")
        //首页
      let homeVC = HOPHomeController()
      self.addchildVC(homeVC, title: "首页", imageName: "tabbar_home")
    
        //消息
        let messageVC = HOPMessageController()
        self.addchildVC(messageVC, title: "消息", imageName: "tabbar_message_center")
        
        //发现
        let discoverVC = HOPDiscoverController()
        self.addchildVC(discoverVC, title: "发现", imageName: "tabbar_discover")
        
        //我
        let profileVC = HOPProfileController()
        self.addchildVC(profileVC, title: "我", imageName: "tabbar_profile")
        
        }
    private func addchildVC(name: UIViewController, title: String, imageName: String) {
    
        self.addChildViewController(UINavigationController(rootViewController: name))
        //设置title
        name.title = title
        //设置图片
        name.tabBarItem.image = UIImage(named: imageName)
        //图片高亮
        let heightImage = imageName + "_highlighted"
        name.tabBarItem.selectedImage = UIImage(named: heightImage)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
    //设置文字颜色
        name.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
          }
    

    
}
